﻿using System;
using System.IO;
using System.Text.RegularExpressions;

class Program
{
    static void Main()
    {
        Console.Write("请输入C#源文件的路径：");
        string filePath = Console.ReadLine();
        if (File.Exists(filePath))
        {
            // Perform the file operations
            Console.WriteLine("File is Found!");
        }
        else
        {
            Console.WriteLine("File not found!");
        }
        int lineCount = CountLines(filePath);
        int wordCount = CountWords(filePath);

        Console.WriteLine($"行数: {lineCount}");
        Console.WriteLine($"词数: {wordCount}");
    }

    static int CountLines(string filePath)
    {
        int count = 0;
        using (StreamReader reader = new StreamReader(filePath))
        {
            while (reader.ReadLine() != null)
            {
                count++;
            }
        }
        return count;
    }

    static int CountWords(string filePath)
    {
        string text = File.ReadAllText(filePath);
        // Remove whitespace, empty lines, and punctuation
        string cleanedText = Regex.Replace(text, @"\s+|[\p{P}-[.]]", " ");

        // Split the cleaned text into words
        string[] words = cleanedText.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

        return words.Length;
    }
}